package com.example.xiaodu.yuejian12.Adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.xiaodu.yuejian12.Activity.ActivityDetailActivity;
import com.example.xiaodu.yuejian12.Bean.ActivityBean;
import com.example.xiaodu.yuejian12.MeIP;
import com.example.xiaodu.yuejian12.MyViewHolder.ItemViewHolder;
import com.example.xiaodu.yuejian12.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by xiaodu on 2018/9/29.
 */

public class ActivityAdapter extends RecyclerView.Adapter {
    private List<ActivityBean>activityBeanList;
    private MeIP ip=new MeIP();
    private String meIP=ip.getIP();

    public void setData(List<ActivityBean> list){
        activityBeanList=list;
        notifyDataSetChanged();
    }

    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){  //展示列表
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View itemView=inflater.inflate(R.layout.activity_item,parent,false);
        ItemViewHolder viewHolder=new ItemViewHolder(itemView);
        return viewHolder;
    }

    public void onBindViewHolder(RecyclerView.ViewHolder holder ,int position){  //显示数据 ，监听
        final ItemViewHolder viewHolder=(ItemViewHolder)holder;
        ActivityBean activityBean=activityBeanList.get(position);
        String name=activityBean.getAcname();
        String time=activityBean.getAtime();
        String place=activityBean.getPlace();
        String pic=activityBean.getApic();

        viewHolder.name.setText("活动名称： "+name);
        viewHolder.time.setText("活动时间： "+time);
        viewHolder.place.setText("活动地点： "+place);
        Picasso.with(viewHolder.imageView.getContext()).load(meIP+"/yuejian/public/static/activity/"+pic).into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                int pos=viewHolder.getLayoutPosition();
                Intent intent=new Intent(v.getContext(), ActivityDetailActivity.class);
                intent.putExtra("activityID",activityBeanList.get(pos).getAcid());
                v.getContext().startActivity(intent);
            }
        });

    }

    public  int getItemCount(){   //
        if (activityBeanList!=null)
            return activityBeanList.size();
        else
            return 0;
    }
}
